<template>
    <el-container class="home-container">
        <!-- 头部区域 -->
        <el-header>
            <span>律所材料管理系统</span>
            <div>
              <el-button type="text"  @click="IndividualCenter">个人中心</el-button>
              <el-button type="text"  @click="logout">退出</el-button>
            </div>
        </el-header>
        <!-- 页面主题区域 -->
        <el-container>
            <!-- 侧边栏 -->
            <el-aside :width="isCocllapse ? '64px':'200px'">
                <div class="toggle-button" @click="toggleCollapse">|||</div>
                <!-- 侧边栏菜单区 -->
                <el-menu
                    background-color="#fff"
                    text-color="#333"
                    :unique-opened="true"
                    :collapse="isCocllapse"
                    :collapse-transition="false"
                    :router="true"
                    :default-active="activePath"
                    active-text-color="#359BFF">
                    <!-- 一级菜单 -->
                    <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
                        <!-- 一级菜单的模块区域 -->
                        <template slot="title">
                            <!-- 图标 -->
                            <i :class="iconsObj[item.id]"></i>
                            <!-- 文本 -->
                            <span>{{ item.authName }}</span>
                        </template>
                        <!-- 二级菜单 -->
                        <el-menu-item :index="'/'+subItem.path" @click="saveNavState('/'+subItem.path)" v-for="subItem in item.children" :key="subItem.id">
                            <template slot="title">
                                <!-- 图标 -->
                                <i class="el-icon-menu"></i>
                                <!-- 文本 -->
                                <span>{{ subItem.authName }}</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <!-- 右侧内容主题 -->
            <el-main>
                <!-- 路由占位符 -->
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
import datas from '@/router/menuList'
import {setToken,getToken,removeToken} from '@/utils/auth.js'
export default {
  data () {
    return {
      menulist: [],
      iconsObj: {},
      // 是否折叠
      isCocllapse: false,
      // 被激活的链接地址
      activePath: ''
    }
  },
  created () {
    this.activePath = window.sessionStorage.getItem('activePath')
    this.menulist = datas.menulist()
    this.iconsObj = datas.iconsObj()
  },
  methods: {
    logout () {
      window.sessionStorage.clear()
      removeToken()
      this.$router.push('/login')
    },
    async getMenuList () {
      const { data: res } = await this.$http.get('menus')
      console.log(res)
      if (res.status !== 200) return this.$message.error(res.message)
      this.menulist = res.data
    },
    toggleCollapse () {
      this.isCocllapse = !this.isCocllapse
    },
    // 保存连接的激活状态
    saveNavState (activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    },
    // 个人中心
    IndividualCenter() {
      this.$router.push('/IndividualCenter')
    }
  }
}
</script>

  <style lang="scss" scoped>
  .home-container {
    height: 100%;
  }
  .el-header {
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #409EFF;
    font-size: 20px;
  }
  .el-aside {
    background-color: #fff;
    .el-menu {
        border-right: none;
    }
    .toggle-button {
        background-color: #FAF7F7;
        font-size: 10px;
        line-height: 24px;
        color: #333;
        text-align: center;
        letter-spacing: 0.2em;
        cursor: pointer;
    }
  }
  .el-main {
    background-color: #E9EDF0;
  }

  </style>
